<?php
require_once 'InfoManager21.php';

$infoManager = new InfoManager();

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $name = $_POST['name'];
    $email = $_POST['email'];
    $phone = $_POST['phone'];
    $address = $_POST['address'];
    $hobby = $_POST['hobby'];

    if ($infoManager->addInfo($name, $email, $phone, $address, $hobby)) {
        header('Location: show_info21.php');
        exit;
    } else {
        $errorMessage = 'Error: 记录插入失败';
    }
}
?>

<!DOCTYPE html>
<html lang="zh-Hans">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>添加信息</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>
    <div class="form-container">
        <h2>添加信息</h2>
        <?php if (isset($errorMessage)) : ?>
            <div class="error-message"><?php echo $errorMessage; ?></div>
        <?php endif; ?>
        <form method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" >
            姓名: <input type="text" name="name"><br><br>
            邮箱: <input type="email" name="email"><br><br>
            电话: <input type="text" name="phone"><br><br>
            地址: <input type="text" name="address"><br><br>
            爱好: <input type="text" name="hobby"><br><br>
            <input type="submit" value="提交">
        </form>
    </div>
</body>
</html>